<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>时间列表</title>
<link rel="stylesheet" type="text/css" href="<%=path %>/style/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/style/icon.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/style/neweasyui/themes/gray/panel.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/style/neweasyui/themes/gray/window.css">
<script type="text/javascript" src="<%=path %>/script/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<%=path %>/script/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=path %>/script/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="<%=path %>/script/dateFormat.js"></script>
<script type="text/javascript" src="<%=path %>/script/datagrid-bufferview.js"></script>
<script type="text/javascript" src="<%=path %>/script/common.js"></script>
<script type="text/javascript" src="<%=path %>/plugins/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
        #fm{
            margin:0;
            padding:10px 30px;
        }
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:80px;
        }
        .fitem input{
            width:160px;
        }
</style>
</head>
<body>
<table id="tt" title="时间列表" style="width:auto;height:800px">
	</table>
	<!-- 工具栏开始 -->
	<div id="toolbar" style="padding:5px;height:auto">
        <div>
        	
        	日期：
        	<input type="text" name="start_time" id="start_time" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="Wdate" style="width:113px"/> - 
        	<input type="text" name="end_time" id="end_time" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" class="Wdate" style="width:113px"/>
            &nbsp;&nbsp;
            类型：<select id="questionType" name="questionType" class="easyui-combobox" panelHeight="auto" style="width:auto" data-options="editable:false "> 
                <option value="" selected="selected">全部</option>
                <option value="0">口语</option>
                <option value="1">写作</option>
            </select>
            &nbsp;&nbsp;
    ID：<input id="sid" name="id" type="text" class="easyui-textbox" style="width:50px">&nbsp;&nbsp;
            题号：<input id="qnum" name="qnum" type="text" class="easyui-textbox" style="width:60px">&nbsp;&nbsp;
            题目：<input id="content" name="content" type="text" class="easyui-textbox" style="width:200px">&nbsp;&nbsp;
    task：<input id="stask" name="task" type="text" class="easyui-textbox" style="width:50px">&nbsp;&nbsp;
    A/B：<input id="sabtype" name="abtype" type="text" class="easyui-textbox" style="width:50px">&nbsp;&nbsp;
           
         <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-search" onclick="searchData()">查询</a>
         <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-add" onclick="newAttr()">添加</a> 
         <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-edit" onclick="editAttr()">修改</a> 
         <a href="javascript:void(0)"  class="easyui-linkbutton" iconCls="icon-remove" onclick="delAttr()">删除</a> 
        </div>
    </div>
    <!-- 工具栏结束 -->
    
    <!-- 添加/编辑框 开始-->
	<div id="dlg" class="easyui-dialog"
		style="width: 600px; height: 450px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons">
		<div class="ftitle">题库信息</div>
		<form id="fm" method="post"  validate>
		    <input type="hidden" name="qaid" id="qaid" />
			<div class="fitem">
				<label>题号:</label>  
			    <input  class="easyui-textbox" name="questionNum" id="questionNum"   required /><span id="errtip"></span>  
			</div>
			
			<div class="fitem">
				<label>task:</label> 
				<input  class="easyui-textbox" name="task" id="questionNum"   />  
			</div>
			
			<div class="fitem">
				<label>A/B:</label> 
				<input  class="easyui-textbox" name="abType" id="questionNum" />
			</div>
			
			<div class="fitem">
				<label>日期:</label> 
				 <input class="easyui-datebox" style="width:165px" name="datetime" id="date_time" data-options="formatter:myformatter,parser:myparser,editable:false "  required></input>
			</div>
			
		</form>
	</div>
	<div id="dlg-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton c6"
			iconCls="icon-ok" onclick="saveOrUpdateQBankAttr()" style="width: 90px">Save</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')"
			style="width: 90px">Cancel</a>
	</div>
	 <!-- 添加/编辑框结束-->
</body>


<script type="text/javascript">
$.ajaxSetup({cache:false});
$(function(){
	$('#tt').datagrid({
		url:'<%=basePath %>question/getQuestionsTime',
		method:'get',
		singleSelect:true,toolbar:'#toolbar',remoteSort:false, pageSize:50,nowrap:false,
		pagination:true,fitColumns:true,
	    columns:[[
	        {field:'id',title:'ID',sortable:true,width:30},
	        {field:'dateTime',title:'日期',sortable:true,width:80,
	        	formatter: Common.DateFormatter,
	        	sorter:Common.DateSorter
	        },     
	        {field:'questionBank.questionNum',title:'题号',sortable:true,width:80,
	        	formatter: function(value,row,index){
	        		return row.questionBank.questionNum;
        		} 
	        },
	        {field:'questionBank.content',title:'题目',sortable:true,width:400,
	        	formatter: function(value,row,index){
	        		return row.questionBank.content;
        		}
	        },
	        
	        {field:'task',title:'Task',sortable:true,width:60},
	        {field:'abType',title:'A/B',sortable:true,width:60},
	        {field:'questionBank.createTime',title:'题库创建时间',sortable:true,width:150,
	        	formatter: function(value,row,index){
	        		return Common.DateFormatterFullTime(row.questionBank.createTime);
        		} 
	        } ,
	        {field:'questionBank.updateTime',title:'题库最后更新时间',sortable:true,width:150,
	        	formatter: function(value,row,index){
	        		return Common.DateFormatterFullTime(row.questionBank.updateTime);
        		} 
	        } 
	    ]]
		});
});

	function searchData(){
		var startTime = $("#start_time").val();
		var endTime = $("#end_time").val();
		var questionType = $("#questionType").combobox("getValue");
		var qnum = $("#qnum").textbox('getValue');
		var content = $("#content").textbox("getValue");
		var id = $("#sid").textbox('getValue') ;
		var task = $("#stask").textbox('getValue') ;
		var abtype= $("#sabtype").textbox('getValue') ;
		
		$('#tt').datagrid({
			url:'<%=basePath %>question/getQuestionsTime?qnum='+qnum+'&questionType='+questionType+'&content='+content+'&startTime='+startTime+'&endTime='+endTime+'&id='+id+'&task='+task+'&abtype='+abtype,
			method:'get',
			onLoadSuccess:function(data){
				if(data.total==0){
					$.messager.alert('提示','没有查询到任何符合条件的数据');
				}
			}
		});
	}
	
	//删除日期属性
	function delAttr(){
		var row = $('#tt').datagrid('getSelected');
		if (row){
            $.messager.confirm('提示','确定要删除这道题吗？',function(r){
                if (r){
                    $.post('<%=basePath%>question/deleteQuestionAttr',{qaid:row.id},function(result){
                        $('#tt').datagrid('reload');    // reload the user data
                    },'json');
                }
            });
   		}
	}
	
    //----------------------------------------------------------------
    
    var url = '' ;
	
	//添加题库属性
	function newAttr(){
		 $('#dlg').dialog('open').dialog('setTitle','添加题库属性');
		 $('#fm').form('clear');
		 $("#questionNum").parent().find('span .textbox-text').removeAttr('readonly') ;
		 url = '<%=basePath%>question/addOrUpdateQuestionBankAttr';
	}
	
	//编辑题库属性
	function editAttr(){
		 var row = $('#tt').datagrid('getSelected');
		 if (row){
			 var qnum = row.questionBank.questionNum ;
			 row.questionNum = qnum ;
			 row.datetime = Common.DateFormatter2(row.dateTime.time)  ;
			 
			 $("#qaid").val(row.id) ;
			 $("#questionNum").parent().find('span .textbox-text').attr('readonly','readonly') ;
			 $('#dlg').dialog('open').dialog('setTitle','编辑题库属性');
			 $('#fm').form('load',row);
			 url = '<%=basePath%>question/addOrUpdateQuestionBankAttr';
		 }
	}
	var flag = true;
	//添加或修改题库
	function saveOrUpdateQBankAttr(){
		
	   $('#fm').form('submit', {
			url : url,
			onSubmit : function() {
				return $(this).form('validate') && flag;
			},
			success : function(result) {
				 
				if (result==0) {
					$.messager.show({
						title : 'Error',
						msg : '服务器出错，请稍后再试'
					});
				} else {
					$('#dlg').dialog('close'); // close the dialog
					$('#tt').datagrid('reload'); // reload the user data
				}
			}
		});
	}
	
	//检查题号是否正确
	function checkQnumIsExist(qnum){
		 
		if(qnum.length>0){
			$.ajax({
				type: 'get'  ,
				url : '<%=basePath%>question/checkQnumIsExist' ,
				data: 'qnum='+qnum ,
				success:function(rs){
					if(rs==1){
						$("#errtip").html("");
						flag = true ;
					}else{
						$("#errtip").html("<font color='red'>&nbsp;&nbsp;该题号不存在!</font>");
						flag = false;
					}
				}
			});
		}
		
	}
	
	$(function(){
		$("#questionNum").parent().find("span .textbox-text").keyup(function(){
		    var qnum = $(this).val();
			if(qnum.length>0){
				checkQnumIsExist(qnum) ;
			}
		});
	});
	
</script>
</html>